package Frame;

import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.event.MouseWheelEvent;
import java.awt.event.MouseWheelListener;

import javax.swing.JDialog;
import javax.swing.JPanel;

import Function.FCActionLibrary;
import Function.FCEventLibrary;

public class FCEventAndActionTable extends JDialog {
	private int w, h, firstnum = 0;

	public <T> FCEventAndActionTable(boolean isevent, FCEventLibrary event, FCActionLibrary actionl) {
		setBounds(0, 0, 1200, 800);
		w = getWidth();
		h = getHeight();
		setLayout(null);
		setLocationRelativeTo(null);
		setResizable(false);
		setModal(true);
		setTitle((isevent) ? "事件列表" : "行为列表");

//		JTabbedPane q=new JTabbedPane();
//		q.setBounds(0, 0, getWidth(), getHeight());
//		this.add(q);

//		new String[] {"ID","描述"}, new String[][] {{"1","12314231"},{"2","1asfwqafagf2314231"}}
//		JTable a=new JTable(ee,ss);
//		q.add(a);
		// 心累，自己做一个表格

		JPanel t = new JPanel() {
			private Color c1 = new Color(220, 220, 220);
			private Font f1 = new Font("黑体", 0, 15);
			private Font f2 = new Font("黑体", 0, 13);

			@Override
			protected void paintComponent(Graphics g) {
//				System.out.println("刷新"+firstnum);
				// 表头
				g.setColor(c1);
				g.fillRect(0, 0, w, 16);
				g.setColor(new Color(240, 240, 240));
				g.fillRect(0, 17, w, h - 17);
				g.setColor(Color.black);
				g.setFont(f1);
				g.drawString("ID", 10, 14);
				g.drawString("描述", 210, 14);
				g.drawLine(200, 0, 200, 16);
				g.drawLine(0, 16, w, 16);
				g.setFont(f2);
				int nn = (isevent) ? event.getEventNum() : actionl.getActionNum();
				for (int i = firstnum; i < nn; i++) {
					g.drawString((isevent) ? event.getEventNameOfID(i) : actionl.getActionNameOfID(i), 5,
							30 + 16 * (i - firstnum));
					g.drawString((isevent) ? event.getEventInfoOfID(i) : actionl.getActionInfoOfNum(i), 210,
							30 + 16 * (i - firstnum));
					g.drawLine(0, 32 + 16 * (i - firstnum), w, 32 + 16 * (i - firstnum));
					g.drawLine(200, 16 + 16 * (i - firstnum), 200, 32 + 16 * (i - firstnum));
				}
			}
		};
		t.setBounds(0, 0, getWidth(), getHeight());
		this.add(t);

		addMouseWheelListener(new MouseWheelListener() {
			@Override
			public void mouseWheelMoved(MouseWheelEvent e) {
				if (e.getWheelRotation() > 0) {
					if (firstnum < event.getEventNum())
						firstnum++;
				} else if (firstnum > 0)
					firstnum--;
				t.updateUI();
			}
		});

		setVisible(true);
	}
}
